/**
 * @filename:BoxingServiceImpl Jan 5, 2024
 * @project Wonder Vue Admin Api  1.1.0
 * Copyright(c) 2022 Wonder Co. Ltd.
 * All right reserved.
 */
package com.wonder.app.service.impl;

import com.wonder.app.domain.Boxing;
import com.wonder.app.mapper.BoxingDao;
import com.wonder.app.service.BoxingService;
import com.wonder.app.request.BoxingRequest;
import com.wonder.common.utils.StringUtils;
import com.wonder.common.utils.MessageUtils;
import com.wonder.common.common.AjaxResult;

import java.util.Date;
import java.util.Map;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * @Description:TODO(波形程序管理服务实现)
 *
 * @version: 1.1.0
 * @author: Wonder
 *
 */
@Service
public class BoxingServiceImpl  extends ServiceImpl<BoxingDao, Boxing> implements BoxingService  {



	@Autowired
	private BoxingService boxingService;
	@Autowired
	private BoxingDao boxingDao;


	/**
	 * 验证波形程序管理信息
	 *
	 * @param boxing
	 * @param type
	 * @return String
	 */
	@Override
	public String validate(Boxing boxing,String type){


		return "";
	}


	/**
	 * Description:波形程序管理分页返回
	 * @param request //检索条件
	 * @param page //分页参数
	 * @return IPage<Boxing>   //分页记录
	 */
	@Override
	public IPage<Boxing> selectList(BoxingRequest request, Page<Boxing> page){
		LambdaQueryWrapper<Boxing> lambdaQueryWrapper = new LambdaQueryWrapper<>();

		if (null != request.getFid()) {
			lambdaQueryWrapper.eq(Boxing::getFid, request.getFid());
		}


		lambdaQueryWrapper.orderByDesc(Boxing::getFid);
		Page<Boxing> selectPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
		return selectPage;
	}

	@Override
	public boolean boxingTiJiao(Long fid) {
		Boxing boxing = boxingDao.selectById(fid);

		//获取提交和审核状态
		boolean tj = boxing.getTijiao();
		boolean sh = boxing.getShenhe();
		boolean res ;

		if(tj == true ){
			res = false;
		}else{
			boxing.setTijiao(true);
			res = boxingService.updateById(boxing);
		}
		return res;
	}
	@Override
	public boolean boxingCheXiao(Long fid) {
		Boxing boxing = boxingDao.selectById(fid);

		//获取提交和审核状态
		boolean tj = boxing.getTijiao();
		boolean sh = boxing.getShenhe();
		boolean res ;
		if(tj == true && sh == false){
			boxing.setTijiao(false);
			res = boxingService.updateById(boxing);
			//true;
		}else{
			res = false ;
		}

		return res;
	}

	@Override
	public boolean boxingShenHe(Long fid) {
		Boxing boxing = boxingDao.selectById(fid);
		//获取提交和审核的状态
		boolean tj = boxing.getTijiao();
		boolean sh = boxing.getShenhe();
		boolean res ;
		Date currentDate = new Date();

		//当提交和审核状态是 true的时候，停止审核操作
		if(tj == true && sh == true  ){
			res = false;
		}
		else if(tj == true && sh == false ){
			boxing.setShenhe(true);
			boxing.setAuditdate(currentDate);
			res = boxingService.updateById(boxing);
		}
		else{
			res = false;
		}
		return res;
	}
	@Override
	public boolean boxingFanShenHe(Long fid) {
		Boxing boxing = boxingDao.selectById(fid);
		//获取提交和审核的状态
		boolean tj = boxing.getTijiao();
		boolean sh = boxing.getShenhe();
		boolean res ;

		if(tj == true && sh == true ){
			boxing.setTijiao(false);
			boxing.setShenhe(false);
			boxingService.updateById(boxing);
			res = true;
		}else {
			res = false;
		}
		return res;
	}

	@Override
	public Map<String, Object> getBoXingByKey(String key, int pageSize) {
		QueryWrapper<Boxing> queryWrapper = new QueryWrapper<>();
		queryWrapper.like("bxbillno",key).or().like("bxname",key);
		Page<Boxing> page = new Page<>();
		page.setSize(pageSize);
		Page<Boxing> page1 = boxingDao.selectPage(page, queryWrapper);
		Map<String,Object> data = new HashMap<>();
		data.put("data",page1);
		return data;
	}

}